package com.android.customized;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.Toast;
import br.com.pierry.simpletoast.SimpleToast;

import com.android.customized.CountDownButtonHelper.OnFinishListener;

public class CountdownButtonHandler extends Handler {
	private Context context;
	private Button codeButton;

	public CountdownButtonHandler(Context context, Button codeButton) {
		this.codeButton = codeButton;
		this.context = context;
	}

	@Override
	public void handleMessage(Message msg) {

		// 启动 倒时计数器
		CountDownButtonHelper helper = new CountDownButtonHelper(this.codeButton, "倒计时", 30, 1);
		helper.setOnFinishListener(new OnFinishListener() {

			@Override
			public void finish() {
				Toast.makeText(context, "倒计时结束", Toast.LENGTH_SHORT).show();
				codeButton.setClickable(true);//激活 按钮
				codeButton.setText("发送验证码");//重新显示发送验证码字样
			}
		});
		helper.start();
		// 显示信息
		SimpleToast.ok(this.context, "发送成功");
		super.handleMessage(msg);
	}
}
